package com.jmu.Shape2;

public class PainRect extends Rect {
    /**
     * 确定位置的矩形
     * 矩形四个角的坐标(默认横着的矩形)：
     *      (startX,startY)         (startX+length,startY)
     *      (startX,startY-wide)    (startX+length,startY-wide)
     */

    //左上角的坐标
    private double startX;
    private double startY;

    public PainRect() {
        super(0,0);
        this.startX = 0;
        this.startY = 0;
    }

    public PainRect(double lenght, double wide, int startX, int startY) {
        super(lenght, wide);
        this.startX = startX;
        this.startY = startY;
    }

    /**
     * 判断点(X,Y)是否在矩形内
     * @param x
     * @param y
     * @return 在矩形内返回true
     */
    public boolean isInside(double x, double y) {
        boolean result = false;
        if ((x >= startX) && (x <= startX+this.getLenght()))
            if ((y <= startY) && (y >= startY-this.getWide()))
                result = true;
        return result;
    }
}
